<?php
class ControllerMessageWeekSituation extends Controller {

	public function all(){
		$this->language->load('message/week_situation');
		$this->load->model('message/week_situation');

		$this->data['weekSituations'] = array();
		/*
		 $week_situations = $this->model_message_week_situation->getWeekSituations();

			$this->document->setTitle("警情通报");
			$this->data['heading_title'] ="警情通报";
			foreach ($week_situations as $week_situation) {
			$this->data['weekSituations'] [] = array(
			'name' => $week_situation['name'],
			'policeSituations'=>$week_situation['policeSituations']
			);

			}
			*/
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}


		$limit = $this->config->get('config_catalog_limit');
		$data = array(
				'start'             => ($page - 1) * $limit,
				'limit'             => $limit
		);

		$total = $this->model_message_week_situation->getTotalPoliceSituationss($data);

		$situations = $this->model_message_week_situation->getPoliceSituationss($data);
		if($situations){
			foreach ($situations as $situation) {
				$this->data['weekSituations'][] = $situation;
			}
		}
		
		$pages = 0;
		$inPages = $total/$limit ;
		$moPages = $total%$limit;
		if($moPages){
			$pages = $inPages+1;
		}else{
			$pages = $inPages;
		}
		
		$this->data['pages'] = $moPages;
		
		
		$more = ($page+1);
		$before = ($page-1);
		$this->data['has_before'] =  true;
		if($before<1){
			$this->data['has_before'] = false;
			$before = 1;
		}
		$this->data['has_more'] = true;
		if($more>$pages){
			$more = $pages;
			$this->data['has_more'] = false;
		}

		
		$this->data['more'] = $this->url->link('message/week_situation/all','page='.$more,'SSL');
		$this->data['before'] = $this->url->link('message/week_situation/all','page='.$before,'SSL');

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/message/week_situation_list.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/message/week_situation_list.tpl';
		} else {
			$this->template = 'default/template/message/week_situation_list.tpl';
		}

		$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
				);

				$this->response->setOutput($this->render());
	}


	public function info() {
		$this->language->load('message/week_situation');

		$this->load->model('message/week_situation');

		$this->data['breadcrumbs'] = array();

		$this->data['breadcrumbs'][] = array(
			'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home'),
			'separator' => false
		);

		if (isset($this->request->get['police_situation_id'])) {
			$police_situation_id = (int)$this->request->get['police_situation_id'];
		} else {
			$police_situation_id = 0;
		}

		$police_info = $this->model_message_week_situation->getPoliceSituationInfo($police_situation_id);
		if ($police_info) {
			$this->document->setTitle($police_info['title']);
			$this->load->model('tool/image');
			$this->data['heading_title'] = $police_info['title'];

			$this->data['title'] = $police_info['title'];
			$this->data['description'] = html_entity_decode($police_info['description'], ENT_QUOTES, 'UTF-8');

			$this->data['continue'] = $this->url->link('common/home');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/message/police_situation.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/message/police_situation.tpl';
			} else {
				$this->template = 'default/template/message/police_situation.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
				);

				$this->response->setOutput($this->render());
		} else {
			$this->data['breadcrumbs'][] = array(
				'text'      => $this->language->get('text_error'),
				'href'      => $this->url->link('message/article', 'police_id=' . $police_id),
				'separator' => $this->language->get('text_separator')
			);

			$this->document->setTitle($this->language->get('text_error'));

			$this->data['heading_title'] = $this->language->get('text_error');

			$this->data['text_error'] = $this->language->get('text_error');

			$this->data['button_continue'] = $this->language->get('button_continue');

			$this->data['continue'] = $this->url->link('common/home');

			$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found');

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}

			$this->children = array(
				'common/column_left',
				'common/column_right',
				'common/content_top',
				'common/content_bottom',
				'common/footer',
				'common/header'
				);

				$this->response->setOutput($this->render());
		}
	}
}
?>